package com.five.controller.backstage;

import com.five.dao.backstage.RoleDao1;
import com.five.entity.backstage.TRole;
import com.five.util.LayTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: 越川豪
 * @Date: 2020/11/25 15:17
 */

@RestController
/**
 *是@Controller和@ResponseBody（返回json数据）的组合注解
 *代表当前的类 返回的全部是json数据
 */
@RequestMapping("role1")
public class RoleController1 {
    @Autowired
    private RoleDao1 roleDao1;

    //查询全部
    @RequestMapping("getAll")
    public LayTable getAll(TRole tRole, Integer page, Integer limit) {
        //查询出所有的角色信息 封装到LayTable里面
        List<Map> roleList = roleDao1.getAll(tRole, page, limit);
        //查询数据条数
        int count = roleDao1.getAllCount(tRole, page, limit);
        LayTable table = new LayTable(count, roleList);
        return table;
    }

    //删除
    @RequestMapping("delRole")
    public Integer deRole(TRole tRole) {
        int i = roleDao1.delRole(tRole);
        return i;
    }

    //修改和添加
    @RequestMapping("updRole")
    public Integer updRole(TRole tRole) {
        int i = roleDao1.updOrAdd(tRole);
        return i;
    }

    //分配权限
    @RequestMapping("updQx")
    public String updQx(Integer rid, String mid) {
        //先删除 此ID的所有权限
        int i = roleDao1.deleteRoleMenu(rid);
        //添加选中的id
        String[] split = mid.split(",");
        for (String s : split) {
            int j = roleDao1.addRoleMenu(s, rid);
        }
        return "1";
    }

    //查看权限
    @RequestMapping("getMenuByRid")
    public List<Map> getMenuByRid(Integer rid) {
        List<Map> map = roleDao1.getMenuByRid(rid);
        return map;
    }


    @RequestMapping("bad")
    public int updata(Integer id){
        int i=roleDao1.bad(id);
        if (i>0){
            return i;
        }
        return -1;
    }
    @RequestMapping("good")
    public int updatagood(Integer id){
        int i=roleDao1.good(id);
        if (i>0){
            return i;
        }
        return -1;
    }
}
